package com.jm.offer.easy;

/**
 * @Description https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
 * @date 2022/4/3 7:53
 */
public class _05替换空格 {
    public static void main(String[] args) {
        String s = "Hello World";
        System.out.println(replaceSpace(s));
    }
    public static String replaceSpace(String s){
        if (!s.contains(" ")){
            return s;
        }
        // 创建一个 stringBuilder对象存储新的字符串
        StringBuilder res = new StringBuilder();
        // 字符串转char数组
        for(Character c : s.toCharArray())
        {
            if(c == ' ') {
                res.append("%20");
            } else {
                res.append(c);
            }
        }
        return res.toString();
    }
}
